<template>
  <view style="width: 100%; height: var(--status-bar-height)" />
  <view class="home">
    <wd-swiper
      v-model:current="current"
      :list="swiperList"
      autoplay
      @click="handleClick"
      @change="onChange"
    />
    <!-- 通知公告 -->
    <wd-notice-bar
      text="吃了吗平台上线了!!"
      color="#34D19D"
      type="info"
    >
      <template #prefix>
        <wd-tag color="#FAA21E" bg-color="#FAA21E" plain custom-style="margin-right:10rpx">
          通知公告
        </wd-tag>
      </template>
    </wd-notice-bar>

    <view class="container margin-top sort-box">
    	<view class="item-box" v-for="(item,i) in sortList" :key="i">
    		<view class="tit" :class="{'active': sortIndex == i}">
    			<text>{{item.tit}}</text>
    		</view>
    	</view>
    </view>
    <view class="store-box" v-if="storeList">
    	<view class=" item-box" v-for="(store,i) in storeList" :key="i">
    		<view class="container top-box">
    			<view class="left" @click="toStore(store,null)">
    				<image :src="store.avatar" mode="aspectFill"></image>
    			</view>
    			<view class="right" @click="toStore(store,null)">
    				
    				<text class="tit" >{{store.name}}（{{store.community}}）</text>
    				<view class="row justify-content">
    					<view class="row-left">
    						<i class="hxicon-favorfill "></i>
    						<text class="t1">{{store.mark}}</text>
    						<text class="t2">月售{{store.monthly_sales}}</text>
    					</view>
    					<view class="row-right">
    						<i class="hxicon-locationfill"></i>
    						<text>{{store.distance}}</text>
    					</view>
    				</view>
    				<view class="row">
    					<text >起送￥{{store.starting_price}}</text>
    					<text class="t2" v-if="store.shipping_dees > 0">配送￥{{store.shipping_dees}} </text>
    					<text class="t2" v-else>免费配送</text>
    				</view>
    				<!-- <view class="row">
    					
    				</view> -->
    			</view>
    		</view>
    		<scroll-view scroll-x  class="bottom-box">
    			<view class="bottom-box-container">
    				<view class="goods-box" v-for="(goods,j) in store.goods" :key="j" @click="toStore(store,goods.id)">
    					<view class="img-box">
    						<image :src="goods.main_pic" mode="aspectFit"></image>
    						<view class="tag">
    							{{goods.tag}}
    						</view>
    					</view>
    					<view class="tit">
    						{{goods.name}}
    					</view>
    					<view class="price-box">
    						<text class="txt1">￥</text>
    						<text class="txt2">{{goods.price}}</text>
    						<text class="txt3">￥{{goods.old_price}}</text>
    					</view>
    				</view>
    			</view>
    			
    		</scroll-view>
    	</view>
    </view>
    <view class="foot" v-if="showFoot">
    	<text>更多商家加入中，敬请期待</text>
    </view>
    <view class="footzw"></view>
  </view>
</template>

<script setup lang="ts">
import { dayjs } from "wot-design-uni";
import testData from "@/common/testdata.js";

import LogAPI, { VisitStatsVO } from "@/api/system/log";

const current = ref<number>(0);
// const shopList = ref<any>();

const showFoot = ref(false);

// 商家排序
const sortIndex = ref(0);
const sortList =  [{tit:'附近商户'}, {tit:'销量'}, {tit:'速度'}, {tit:'配送费'}];
const storeList = reactive([]);		

// 日期范围
const recentDaysRange = ref(7);

const swiperList = ref(["https://www.youlai.tech/storage/blog/banner9.png"]);

function handleClick(e: any) {
  console.log(e);
}
function onChange(e: any) {
  console.log(e);
}
function toStore(store: any, goodsID: number){
	let store_id = store.store_id
	let parameter = `?sid=${store_id}`
	
	if(goodsID != null){
		parameter += `&gid=${goodsID}`
	}
	uni.navigateTo({
		url: '/pages/store/index' + parameter
	})
};

// 加载商家数据
const loadShopsData = async () => {
  Object.assign(storeList, testData.storeList);
  LogAPI.getVisitStats().then((data) => {
    // shopList.value = data;
  });
};

onReady(() => {
	loadShopsData();
});
</script>

<style setup lang="scss">
.home {
  padding: 10rpx 10rpx;
  :deep(.custom-item) {
    height: 80px !important;
  }
  :deep(.wd-card) {
    margin: 10rpx 0 !important;
  }
}

.charts-box {
  width: 100%;
  height: 300px;
}

.menu-box{
	
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	margin-top: 12px;
	border-radius: 8px;
	background: #ffffff;
	padding: 12px 8px;
	.item-box{
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		image{
			width: 40px;
			height: 40px;
		}
		.tit{
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 12px;
			margin-top: 6px;
			color: #333333;
			padding: 2px 0;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
		}
		.active{
			color: #ffffff;
			background-color: #999999;
			border-radius: 60px;
		}
	}
}
.sort-box{
	display: flex;
	flex-direction: row;
	margin-top: 12px;
	.item-box{
		
		margin-right: 16px;
		.tit{
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 12px;
			color: #333333;
			white-space: nowrap;
			overflow: hidden;
			text-overflow: ellipsis;
		}
		.active{
			//color: #111111;
			font-weight: bold;
		}
	}
}
.store-box{
	margin-top: 20px;
	
	.item-box{
		display: flex;
		flex-direction: column;
		margin-bottom: 14px;
		padding-bottom: 18px;
		padding-top: 18px;
		background-color: #ffffff;
		.top-box{
			display: flex;
			flex-direction: row;
			.left{
				margin-right: 10px;
				
				
				image{
					width: 72px;
					height: 54px;
					border-radius: 6px;
				}
			}
			.right{
				flex: 1;
				.tit{
					font-size: 16px;
					font-weight: bold;
					color: #333333;
					white-space: nowrap;
					overflow: hidden;
					text-overflow: ellipsis;
				}
				.justify-content{
					display: flex;
					flex-direction: row;
					justify-content: space-between;
				}
				.row{
					font-size: 12px;
					color: #999999;
					margin-top: 4px;
					.row-left{
						display: flex;
						flex-direction: row;
						.t1,i{
							color: #ffca3e;
						}
						
					}
					.t2{
						margin-left: 12px;
					}
					.row-right{
						display: flex;
						flex-direction: row;
						i{
							margin-right: 4px;
						}
					}
					
				}
			}
		}
		.bottom-box{
			&-container{
				margin: 12px 0 0;
				padding-left: 82px;
				
				white-space: nowrap;
				.goods-box{
					width: 80px;
					margin-left: 12px;
					display: inline-block;
					.img-box{
						position: relative;
						width: 80px;
						height: 60px;
						background-color: #f1f1f1;
						border-radius: 4px;
						image{
							width: 100%;
							height: 60px;
						}
						.tag{
							position: absolute;
							bottom: 0;
							left: 0;
							background-color: #FF5722;
							color: #ffffff;
							padding: 2px 4px;
							font-size: 12px;
							border-radius: 4px;
						}
					}
					.tit{
						font-size: 14px;
						margin-top: 4px;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}
					.price-box{
						margin-top: 4px;
						.txt1{
							font-size: 10px;
							color: #FF5722;
						}
						.txt2{
							font-size: 16px;
							color: #FF5722;
						}
						.txt3{
							margin-left: 6px;
							font-size: 10px;
							color: #bbbbbb;
							text-decoration: line-through;
						}
					}
				}
				.goods-box:last-child{
					margin-right: 12px;
				}
				
			}
			
		}
	}
	.item-box:last-child{
		border-bottom: 0;
	}
}
.foot{
	position: relative;
	display: flex;
	justify-content: center;
	margin-top: 36px;
	margin-bottom: 50px;
	text{
		font-size: 14px;
		position: relative;
		z-index: 2;
		height: 20px;
		line-height: 20px;
		background-color: #f8f8f8;
		color: #cccccc;
		padding: 0 12px;
	}
}
.foot::before{
	content: "";
	z-index: 1;
	display: block;
	position: absolute;
	top: 50%;
	height: 0;
	width: 100%;
	transform: scaleY(0.5);
	border-bottom: 1px solid #E4E7ED;
}
.footzw{
	/* #ifdef H5*/
	height: 50px;
	/* #endif */
}
</style>
